ELEMENTS

Editing
  • account_tree
  • bug_report

<select>

정해진 옵션 중에서 선택하는 방식으로 입력을 할 수 있는 컨트롤을 나타낸다.

  • 콘텐츠 분류

  • 허용된 부모 요소 또는 위치

    PHRASING CONTENT

    구문 콘텐츠(phrasing-content)가 예상되는 위치

  • 허용된 자식 요소

    SCRIPT SUPPORTING, <OPTGROUP>, <OPTION>

    0개 이상의 <option>, <optgroup>, <hr> 요소 및 스크립트 지원(script-supporting) 요소

  • 태그 생략

    시작 태그, 종료 태그 모두 작성

  • DOM Interface

    HTMLSelectElement

    [Exposed=Window]
    interface HTMLSelectElement : HTMLElement {
      [HTMLConstructor] constructor();
    
      [CEReactions] attribute DOMString autocomplete;
      [CEReactions] attribute boolean disabled;
      readonly attribute HTMLFormElement? form;
      [CEReactions] attribute boolean multiple;
      [CEReactions] attribute DOMString name;
      [CEReactions] attribute boolean required;
      [CEReactions] attribute unsigned long size;
    
      readonly attribute DOMString type;
    
      [SameObject] readonly attribute HTMLOptionsCollection options;
      [CEReactions] attribute unsigned long length;
      getter HTMLOptionElement? item(unsigned long index);
      HTMLOptionElement? namedItem(DOMString name);
      [CEReactions] undefined add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
      [CEReactions] undefined remove(); // ChildNode overload
      [CEReactions] undefined remove(long index);
      [CEReactions] setter undefined (unsigned long index, HTMLOptionElement? option);
    
      [SameObject] readonly attribute HTMLCollection selectedOptions;
      attribute long selectedIndex;
      attribute DOMString value;
    
      readonly attribute boolean willValidate;
      readonly attribute ValidityState validity;
      readonly attribute DOMString validationMessage;
      boolean checkValidity();
      boolean reportValidity();
      undefined setCustomValidity(DOMString error);
    
      readonly attribute NodeList labels;
    };

구문

마크업 형식
<select> <option></option> <option></option>
</select>
Example

애트리뷰트

autocomplete keywords and enumerated attributes

양식(form) 내에 있는 입력 요소들의 자동 채우기 설정을 지정한다. 자동 채우기는 다음과 같이 두 가지 방식이 가능하다.

자동 완성 기대 맨틀(autofill expectation mantle)
사용자로부터 예상되는 입력을 나타낸다. 설정하는 방법은 on 키워드는 활성되고 off 키워드는 비활성된다. 생략될 수 있으며 생략되거나 유효하지 않은 경우에 기본값은 on이다. type 애트리뷰트가 hidden이 아닌 경우 사용된다.
자동 완성 앵커 맨틀(autofill anchor mantle)
주어진 값의 의미를 설명한다. 자동 완성 세부 토큰으로 구성된 공백으로 구분된 토큰의 정렬된 집합인 값을 가져야 한다. onoff 키워드는 사용할 수 없다. type 애트리뷰트가 hidden인 경우 사용된다.

지금까지의 내용은 HTML Standard 표준 사양에 나와있는 내용이지만 자동 완성 앵커 맨틀(autofill anchor mentle)에 대해 다음과 같은 이슈가 있다.

  • typehidden인 요소에게 자동 완성 기능 적용이 올바른가? [open issue]
  • 유저 에이전트에서의 동작 지원 여부가 명확하지 않다.

현재로서는 이 이슈에 대해 앞으로 시간을 두고 확인이 필요해 보이며 일반적인 자동 완성 기능인 자동 완성 기대 맨틀(autofill expectation mantle)의 구현을 위한 애트리뷰트라고 보는 편이 나을 것 같다.

기본값

on
disabled boolean attributes

요소를 비활성화한다.

About Boolean attributes

불리언(boolean) 값을 나타낸다. 예를 들어 다음 세 가지 값은 모두 참(true)이다.

<input disabled>, <input disabled="disabled">, <input disabled="">

form unique identifier

<form> 요소와 연결할 때 연결하고자 하는 <form> 요소의 id를 지정한다.

About Unique identifier

문서에서 요소를 식별하는 유일무이한 문자열 값을 나타낸다.

multiple boolean attributes

두 개 이상의 값을 지정할 수 있는 여부를 나타낸다.

About Boolean attributes

불리언(boolean) 값을 나타낸다. 예를 들어 다음 세 가지 값은 모두 참(true)이다.

<input disabled>, <input disabled="disabled">, <input disabled="">

이 요소에서의 특징

multiple을 지정하면 size 애트리뷰트 적절한 크기로 지정해야만 두 개 이상의 선택이 가능하다.

사용 예

name non empty string

요소의 이름을 지정한다. 유저 에이전트(user agent)에서 식별값으로 사용되며 입력 요소에 지정된 name의 값은 서버에 전송시 데이터를 식별하는 이름으로 사용된다. 식별값으로 사용되지만 유일무이한 값으로 강제하지는 않는다. 그러한 이유는 <input type="checkbox"> 요소를 통해 이해할 수 있다. 체크박스 입력 방식은 준비된 동일한 이름의 데이터에서 다른 값을 선택하는 식이다. 따라서 값은 달라도 데이터의 이름은 동일할 수 있다.

<form> 요소에서 name 애트리뷰트가 HTML5에서 폐기되었다. 대신에 id 애트리뷰트를 식별값으로 사용한다.
About Non empty string

비워있지 않는 문자열을 나타낸다.

required boolean attributes

필수로 입력해야 할 입력 요소로 지정할지 여부를 나타낸다. 지정이 되면 필수 입력 요소가 된다.

About Boolean attributes

불리언(boolean) 값을 나타낸다. 예를 들어 다음 세 가지 값은 모두 참(true)이다.

<input disabled>, <input disabled="disabled">, <input disabled="">

size non-negative integers

사용자에게 표시할 옵션의 수를 지정한다. 0보다 큰 음수가 아닌 유효한 정수 값이어야 한다. 기본값은 1이며 multiple 애트리뷰트가 지정되면 4가 된다.

About Non-negative integers

음수가 아닌 유효한 정수를 나타낸다.

사용 예

글로벌 애트리뷰트

일부 글로벌 애트리뷰트는 이 요소에서 사용되지 않을 수 있다.

글로벌 이벤트 핸들러

일부 글로벌 이벤트 핸들러는 이 요소에서 사용되지 않을 수 있다. 이벤트 등록은 자바스크립트 사용을 권장한다.

버전 명세

HTML Standard
#the-select-element

지원 웹브라우저